<?php

namespace app\admin\model;

use think\Model;

/**
 * 位置表
 * @package app\admin\model
 */
class Location extends Model
{
    # 设置当前模型对应的完整数据表名称
    protected $name = 'admin_location';

    # 自动写入时间戳
    protected $autoWriteTimestamp = true;


    /**
     * 获取省
     * @return array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getProvince($field='*')
    {
        $data = self::where('type',1)->field($field)->select();
        $data = empty($data) ? []: $data->toArray();
        return $data;
    }

    /**
     * 获取市
     * @param $pid
     * @return array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getCity($pid,$field='*')
    {
        $data = self::where('type',2)->where('pid',$pid)->field($field)->select();
        $data = empty($data) ? []: $data->toArray();
        return $data;
    }


    /**
     * 获取区
     * @param $pid
     * @return array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getArea($pid,$field='*')
    {
        $data = self::where('type',3)->where('pid',$pid)->field($field)->select();
        $data = empty($data) ? []: $data->toArray();
        return $data;
    }

}